//
//  BKMathingScoreDataSource.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/5/31.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKMathingScoreDataSource.h"

@implementation BKMathingScoreDataSource

- (id)init{

    self = [super init];
    if (self) {
        _selectedArray = [NSMutableArray array];
        _isComparing = NO;
    }
    return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return    [_dataArray count];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BKMatchingScoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuserIdentify];
    
    NSDictionary *dic = _dataArray[indexPath.row];
    cell.h14Label.text = dic[@"14h"];
    cell.h13Label.text = dic[@"13h"];
    cell.h12Label.text = dic[@"12h"];
    
    cell.l14Label.text = dic[@"14l"];
    cell.l13Label.text = dic[@"13l"];
    cell.l12Label.text = dic[@"12l"];
    
    cell.a14Label.text = dic[@"14a"];
    cell.a13Label.text = dic[@"13a"];
    cell.a12Label.text = dic[@"12a"];
    
    cell.nameLabel.text = dic[@"name"];
    cell.pipeidu.text = dic[@"ppd"];
    
    if (indexPath.row%2==0) {
        cell.backgroundColor = [UIColor clearColor];
    }else{
        cell.backgroundColor = [UIColor colorWithRed:0.922 green:0.965 blue:0.980 alpha:1.000];
    }
    
    cell.selected = NO;
    __block BOOL isSelected = NO;
    __weak BKMathingScoreDataSource *weakSelf = self;
    [_selectedArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj[@"cid"] isEqualToString:weakSelf.dataArray[indexPath.row][@"cid"]]) {
            *stop = YES;
            isSelected = YES;
        }
        
        
    }];
    
    if (_isComparing) {
        cell.selectImageLayout.constant = 20;
        cell.nameWidthLayout.constant = 78;
        [cell layoutIfNeeded];
        cell.isSelecteImageView.hidden = NO;
        if (isSelected) {
            cell.isSelecteImageView.image = [UIImage imageNamed:@"selected"];
        }else{
            
            cell.isSelecteImageView.image = [UIImage imageNamed:@"unselected"];
        }
        

    }else{
    
        cell.selectImageLayout.constant = 0;
         cell.nameWidthLayout.constant = 98;
        [cell layoutIfNeeded];

        cell.isSelecteImageView.hidden = YES;
    }
    
        return cell;
    
    

}


@end
